package p.ithorns.integration.transform.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import p.ithorns.framework.common.uuid.SnowFlakeId;
import p.ithorns.integration.transform.entity.*;
import p.ithorns.integration.transform.enums.OrderType;
import p.ithorns.integration.transform.mapper.OrderMapper;
import p.ithorns.tools.translator.annotation.Translatable;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Description:
 * <p>OrderServiceImpl</p>
 * Created By Ht_L. 2019/4/22-18:03
 */
@Slf4j
@Service
public class OrderService extends ServiceImpl<OrderMapper, Order> {

    @Autowired
    private OrderMapper mapper;

    static SnowFlakeId idGenerator = new SnowFlakeId(1, 1);

    @Translatable
    public Order get(Integer id) {
        Order order = new Order();
        order.setUserName("xxx");
        order.setId(id);
        order.setType(OrderType.random().getCode());
        return order;
    }

    public Order add(Order order) {
        mapper.insert(order);
        log.info("----> save success: {}", order);
        return order;
    }

    public void update(Order order) {
        log.info("----> update success: {}", order);
    }

    public void remove(Serializable id) {
        mapper.deleteById(id);
    }

}